﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace ExtraFoundation.Components
{
    public class MeshArray
    {
        public static void Add<T>(ref T[] a, T[] b)
        {
            if (a == null)
            {
                a = new T[0];
                // throw new NullReferenceException();
            }

            if (b == null)
            {
                b = new T[0];
            }
            
            T[] c = new T[a.Length + b.Length];
            int i = 0;
            while (i < a.Length)
            {
                c[i] = a[i];
                i++;
            }
            
            while (i < c.Length)
            {
                c[i] = b[i - a.Length];
                i++;
            }
            a = c;
        }

        public static void Add(ref int[] a, int[] b, int offset = 0)
        {if (a == null)
            {
                a = new int[0];
                // throw new NullReferenceException();
            }

            if (b == null)
            {
                b = new int[0];
            }
            
            int[] c = new int[a.Length + b.Length];
            int i = 0;
            while (i < a.Length)
            {
                c[i] = a[i];
                i++;
            }
            
            while (i < c.Length)
            {
                c[i] = b[i - a.Length] + offset;
                i++;
            }
            a = c;
            
        }
        
        
    }
}